<?php

namespace App\Http\Controllers\Teaching;

use App\Common\Utils\JsonResponse;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class LiveController extends Controller
{
    /** @var \App\Services\System\LogService $logService */
    private $logService;
    /** @var \App\Services\Teaching\LiveService $liveService */
    private $liveService;

    /**
    * Create a new controller instance.
    *
    * @return void
    */
    public function __construct()
    {
        parent::__construct();
        $this->middleware('auth');
        $this->logService = app('logService');
        $this->liveService = app('liveService');
    }

    /**
     * @Description: 获取直播管理列表信息数据
     * @Author: kzj
     * @datetime: 2023-03-15
     */
    public function getList(Request $request)
    {
        try
        {
            $result = $this->liveService->getList($request->all());
            $this->logService->log('255', '直播管理查看', '直播管理查看');
            return JsonResponse::get($result['data'], TRUE, $result['total'], $result['per_page']);
        }
        catch(\Exception $e)
        {
            return $this->error($e);
        }
    }

    /**
     * @Description: 直播管理添加
     * @Author: kzj
     * @datetime: 2023-03-15
     */
    public function add(Request $request)
    {
        try{
            $result = $this->liveService->add($request->all());
            $this->logService->log('256', '直播管理添加', '直播管理添加');
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 直播管理单条数据
     * @Author: kzj
     * @datetime: 2023-03-15
     */
    public function one(Request $request)
    {
        try{
            $result = $this->liveService->one($request->all());
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 直播管理编辑
     * @Author: kzj
     * @datetime: 2023-03-15
     */
    public function edit(Request $request)
    {
        try{
            $result = $this->liveService->edit($request->all());
            $this->logService->log('257', '直播管理编辑', '直播管理编辑');
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 直播管理删除
     * @Author: kzj
     * @datetime: 2023-03-15
     */
    public function del(Request $request)
    {
        try{
            $result = $this->liveService->del($request->all());
            $this->logService->log('259', '直播管理删除', '直播管理删除');
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }
}
